package neusoft.yuejian_11.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.IsAddPrize;
import neusoft.yuejian_11.bean.IsAttentionBean;
import neusoft.yuejian_11.bean.PrizeBean;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.UserModel;
import neusoft.yuejian_11.R;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

//奖品详情（已改）
public class PrizeDetailActivity extends BaseActivity implements RetrofitListener {
    protected Context context;
    private int giftId;
    private Button duijianganniu;
    private TextView giftnameView;
    private TextView giftinfoView;
    private TextView giftvalueView;
    private ImageView g_pic;
    private ImageButton imageButtonBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prize_detail);
        initView();
        initData();

        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
    private void initData() {
        giftId = getIntent().getIntExtra("g_id",-1);
        UserModel userModel = new UserModel();
        userModel.PrizeByIdDetail(String.valueOf(giftId),this);
        UserModel userModel2=new UserModel();
        userModel2.IsAddPrize(String.valueOf(u_id),String.valueOf(giftId),this);
    }

    private void initView() {
        duijianganniu= (Button) findViewById(R.id.addprize);
        giftnameView = (TextView) findViewById(R.id.giftname);
        giftinfoView = (TextView) findViewById(R.id.giftinfo);
        giftvalueView= (TextView) findViewById(R.id.giftvalue);
        g_pic= (ImageView) findViewById(R.id.giftpic);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
    }

    @Override
    public void onSuccess(Object o, int flag) {
if(flag==1) {
    PrizeBean prizeBean = (PrizeBean) o;
    giftnameView.setText(prizeBean.getG_name());
    giftvalueView.setText(prizeBean.getG_values());
    giftinfoView.setText(prizeBean.getG_info());
    Picasso.with(context)
            .load(BASE_URI + "giftpic/" + prizeBean.getG_pic())
            .into(g_pic);
}

        //判断这个奖品是否被兑换过
        if (flag == 4) {
            IsAddPrize isAddPrize = (IsAddPrize) o;
            if (isAddPrize.getGr_state().equals("未发货")) {
                //已兑换，未发货
                Toast.makeText(PrizeDetailActivity.this, "该奖品已经兑换过，未发货", Toast.LENGTH_SHORT).show();

            }
            if (isAddPrize.getGr_state().equals("已发货")){
                //已兑换已发货
                Toast.makeText(PrizeDetailActivity.this, "该奖品已经兑换过，已发货", Toast.LENGTH_SHORT).show();

            }
            if (isAddPrize.getGr_state().equals("未兑换")){
                //未兑换过
                duijianganniu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(PrizeDetailActivity.this,AddPrizeActivity.class);
                        intent.putExtra("g_id",giftId);
                        startActivity(intent);
                    }
                });
            }
        }
    }

    @Override
    public void onFail() {

    }

}
